<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
		<meta charset="utf-8" />
		<title>驴妈妈流立方</title>
		<meta name="description" content="overview &amp; stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="${request.contextPath}/assets/css/bootstrap.min.css" />
		<link rel="stylesheet" href="${request.contextPath}/assets/font-awesome/4.7.0/css/font-awesome.min.css" />
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="${request.contextPath}/assets/css/daterangepicker.min.css" />
		<link rel="stylesheet" href="${request.contextPath}/assets/css/jquery.gritter.min.css" />
		<!-- text fonts -->
		<link rel="stylesheet" href="${request.contextPath}/assets/css/fonts.googleapis.com.css" />
		<!-- ace styles -->
		<link rel="stylesheet" href="${request.contextPath}/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
		<link rel="stylesheet" href="${request.contextPath}/assets/css/ace-skins.min.css" />
		<link rel="stylesheet" href="${request.contextPath}/assets/css/ace-rtl.min.css" />
		<!-- ace settings handler -->
		<script src="${request.contextPath}/assets/js/ace-extra.min.js"></script>
		<link rel="stylesheet" href="${request.contextPath}/assets/css/bsie-paginator.css" />
		<style>
			tr.detail-row {
				display: none
			}
			tr.detail-row.open {
				display: block;
				display: table-row
			}
		</style>
		<script src="${request.contextPath}/assets/js/jquery-2.1.4.min.js"></script>
		<script type="text/javascript">
            if('ontouchstart' in document.documentElement) document.write("<script src='${request.contextPath}/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="${request.contextPath}/assets/js/bootstrap.min.js"></script>
		<script src="${request.contextPath}/assets/js/jquery-ui.custom.min.js"></script>
		<script src="${request.contextPath}/assets/js/jquery.ui.touch-punch.min.js"></script>
		<script src="${request.contextPath}/assets/js/bootbox.min.js"></script>
		<script src="${request.contextPath}/assets/js/jquery.gritter.min.js"></script>
		<script src="${request.contextPath}/assets/js/spin.min.js"></script>
		<!-- ace scripts -->
		<script src="${request.contextPath}/assets/js/ace-elements.min.js"></script>
		<script src="${request.contextPath}/assets/js/ace.min.js"></script>
		<!-- validator scripts -->
		<script src="${request.contextPath}/assets/js/bootstrapValidator.min.js"></script>
		<!-- user scripts -->
		<script src="${request.contextPath}/assets/js/user/base.js"></script>
	</head>

	<body class="skin-2" style="background-color: #FFF;">
		<div class="page-content">
			<div class="row">
				<div class="col-sm-12">
					<div class="row">
						<div class="col-xs-12">
							<div class="clearfix">
								<div class="pull-left tableTools-container">
									<button class="btn btn-xs btn-primary" onclick="skip('${request.contextPath}/statisticCode/new')"><i class="ace-icon fa fa-pencil-square-o align-top bigger-125"></i>新增</button>
								</div>
							</div>
							<div class="tab-pane in active" id="codeList">
								<div id="dynamic-table_wrapper" class="dataTables_wrapper form-inline no-footer">
									<div class="row">
										<form class="form-inline" id="searchForm" method="post" action="${request.contextPath}/statisticCode/list">
											<input type="hidden" name="currentPage" value=1 id=""/>
											<input type="hidden" name="pageSize" value="10" id="pageSize" />
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>父级名称
														<input type="text" class="form-control" name="parentName" value="${statisticCodesConditionVO.parentName!}" placeholder="模糊查询父级名称">
													</label>
												</div>
											</div>
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>中文名称
														<input type="text" class="form-control" name="name" value="<#if statisticCodesConditionVO ?? >${statisticCodesConditionVO.name!}</#if>" placeholder="模糊查询中文名称">
													</label>
												</div>
											</div>
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>名称拼音
														<input type="text" class="form-control" name="enName" value="<#if statisticCodesConditionVO ?? >${statisticCodesConditionVO.enName!}</#if>" placeholder="模糊查询名称拼音">
													</label>
												</div>
											</div>
											<div class="col-xs-2">
												<div class="dataTables_length">
													<label>code码
														<input type="text" class="form-control" name="code" value="<#if statisticCodesConditionVO?? >${statisticCodesConditionVO.code!}</#if>" placeholder="模糊查询code码">
													</label>
												</div>
											</div>
											<div class="col-xs-3 col-sm-3">
												<div class="dataTables_length">
													<button type="submit" class="btn btn-pink btn-sm" id="search">
														<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
														查询
													</button>
												</div>
											</div>
										</form>
									</div>
									<table id="dynamic-table" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dynamic-table_info">
										<thead>
											<tr>
												<th>No.</th>
												<th>父级名称</th>
												<th>中文名称</th>
												<th>名称拼音</th>
												<th>code码</th>
												<th>添加子级</th>
												<th>code码类型</th>
												<th>类型级别</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody>
											<#if statisticCodes?? && statisticCodes?size&gt;0>
												<#list statisticCodes as statisticCode>
												<tr class="">
													<td>${statisticCode_index + 1}</td>
													<td><#if statisticCode ??  && statisticCode.parent ??>${statisticCode.parent.name!}</#if></td>
													<td>${statisticCode.name!}</td>
													<td>${statisticCode.enName!}</td>
													<td><#if statisticCode.parentId?? && statisticCode.parentId == 434>
														${statisticCode.code!}&nbsp;&nbsp;&nbsp;<i class="normal-icon ace-icon fa fa-eye green bigger-130" onclick="showimage('${request.contextPath}/assets/images/pit.png')"></i>

													<#else>${statisticCode.code!}</#if></td>
													<td><#if statisticCode.isAdd?? && statisticCode.isAdd== '1'>允许<#else>不允许</#if></td>
													<td>${statisticCode.codeType!}</td>
													<td>${statisticCode.codeTypeLevel!}</td>
													<td>
														<a class="btn btn-minier btn-primary" onclick="updateCode(this);" value="${statisticCode.id!}" role="button">编辑</a>
													</td>
												</tr>
											</#list>
											<#else>
												<tr>
													<td colspan="12">
														<div class="alert alert-danger" style="margin-bottom: 0px;" role="alert">没有记录!</div>
													</td>
												</tr>
											</#if>
										</tbody>
									</table>
									<div class="ui-jqgrid">
										<div id="grid-pager"
											 class="ui-state-default ui-jqgrid-pager ui-corner-bottom" dir="ltr">
											<div id="pg_grid-pager" class="ui-pager-control" role="group">
												<table cellspacing="0" cellpadding="0" border="0" class="ui-pg-table"
													   style="width: 100%; table-layout: fixed; height: 100%;" role="row">
													<tbody>
													<tr>
														<td id="grid-pager_left" align="left"></td>
														<td id="grid-pager_center" align="center"
															style="white-space: pre; width: 343px;"><table
																cellspacing="0" cellpadding="0" border="0"
																style="table-layout: auto;" class="ui-pg-table">
															<tbody>
															<tr>
																<td id="first_grid-pager" onclick="showPage(1,this)"
																	class="ui-pg-button ui-corner-all <#if page.isFirstPage>ui-state-disabled</#if>"
																	style="cursor: pointer;"><span
																		class="ui-icon ace-icon fa fa-angle-double-left bigger-140"></span></td>
																<td id="prev_grid-pager" onclick="showPage(${page.prePage!},this)"
																	class="ui-pg-button ui-corner-all <#if page.isFirstPage>ui-state-disabled</#if>"
																	style="cursor: pointer;"><span
																		class="ui-icon ace-icon fa fa-angle-left bigger-140"></span></td>
																<td dir="ltr">Page <input class="ui-pg-input" type="text"
																						  size="2" maxlength="7" value="${page.pageNum!}" role="textbox"> of <span
																		id="sp_1_grid-pager">${page.pages!}</span></td>
																<td id="next_grid-pager" onclick="showPage(${page.nextPage!},this)" class="ui-pg-button ui-corner-all <#if page.isLastPage>ui-state-disabled</#if>"
																	style="cursor: pointer;"><span
																		class="ui-icon ace-icon fa fa-angle-right bigger-140"></span></td>
																<td id="last_grid-pager" onclick="showPage(${page.pages!},this)" class="ui-pg-button ui-corner-all <#if page.isLastPage>ui-state-disabled</#if>"
																	style="cursor: pointer;"><span
																		class="ui-icon ace-icon fa fa-angle-double-right bigger-140"></span></td>
															</tr>
															</tbody>
														</table></td>
														<td id="grid-pager_right" align="right"><div dir="ltr"
																									 style="text-align: right" class="ui-paging-info">View ${page.startRow!} -
															${page.endRow!} of ${page.total!}</div></td>
													</tr>
													</tbody>
												</table>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-xs-12">
							<button class="btn btn-info" data-toggle="modal" type="button" style="display:none;" id="update"
								   data-target="#myModal" <#if statisticCode?? && statisticCode.id??>disabled='true' readOnly='true'</#if>>
							</button>
							<form id="updateCode" class="form-horizontal" role="form">
							<div class="modal fade" id="myModal" tabindex="-1" role="dialog" 
								   aria-labelledby="myModalLabel" aria-hidden="true">
								   <div class="modal-dialog">
								      <div class="modal-content">
								         <div class="modal-header">
								            <button type="button" class="close" 
								               data-dismiss="modal" aria-hidden="true">
								                  &times;
								            </button>
								            <h4 class="modal-title" id="myModalLabel">
								               	编辑code
								            </h4>
								         </div>
							         <div class="modal-body">
										<input type="hidden" id="id" name="id" value="<#if statisticCode ?? && statisticCode.id>${statisticCode.id!}</#if>">
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>父级code码 </label>
											<div class="col-sm-8">
												<input type="hidden" id="parent" name="parent" value="<#if statisticCode ?? && statisticCode.parent ?? && statisticCode.parent.id ??>${statisticCode.parent.id!}</#if>">
												<input type="text" id="parentText" name="parentText" placeholder="请选择父级code码" value="<#if statisticCode ?? && statisticCode.parent ??>${statisticCode.parent!}</#if>" class="col-xs-12 col-sm-6" disabled='true' readOnly='true'>
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>中文名称 </label>
											<div class="col-sm-8">
												<input type="text" id="name" name="name" placeholder="请输入名称" value="<#if statisticCode ?? && statisticCode.name ??>${statisticCode.name!}</#if>" class="col-xs-12 col-sm-6" >
												<input type="hidden" id="nameBak" name="nameBak" value="">
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>名称拼音 </label>
											<div class="col-sm-8">
												<input type="text" id="enName" name="enName" placeholder="请输入名称拼音" value="<#if statisticCode ?? && statisticCode.enName ??>${statisticCode.enName!}</#if>" class="col-xs-12 col-sm-6" >
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>code码 </label>
											<div class="col-sm-8">
												<input type="text" id="code" name="code"  value="<#if statisticCode ?? && statisticCode.code ??>${statisticCode.code!}</#if>" class="col-xs-12 col-sm-6" disabled='true' readOnly='true'>
											</div>
										</div>
										<div class="space-4"></div>
										<div class="form-group">
											<label class="col-sm-4 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>添加子级 </label>
											<div class="col-sm-3">
												<select class="form-control" name="isAdd" id="isAdd">
													<option value="1">允许</option>
													<option value="0">不允许</option>
												</select>
											</div>
										</div>
							         </div>
							         <div class="modal-footer">
							            <button type="button" class="btn btn-default"
							               data-dismiss="modal">关闭
							            </button>
							            <button id="save" type="button" class="btn btn-primary" >
							              	 提交
							            </button>
							         </div>
							      </div><!-- /.modal-content -->
								</div><!-- /.modal -->
							</div>
							</form>
						</div>
					</div>
					<div id="ShowImage_Form" class="modal">
						<div class="modal-header">
							<button data-dismiss="modal" class="close" type="button"></button>
						</div>
						<div class="modal-body">
							<div id="img_show">
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>


		<script type="text/javascript">
            $(function () {
                MergeCell('dynamic-table', 1, 0, 0);
                //A('dynamic-table', 1);
            })

            function MergeCell(tableId, startRow, endRow, col) {
                var tb = document.getElementById(tableId);
                if (col >= tb.rows[0].cells.length) {
                    return;
                }
                //当检查第0列时检查所有行
                if (col == 0 || endRow == 0) {
                    endRow = tb.rows.length - 1;
                }

                for (var i = startRow; i < endRow; i++) {
                    //程序是自左向右合并
                    if (tb.rows[startRow].cells[col].innerHTML == tb.rows[i + 1].cells[col].innerHTML) {
                        //如果相同则删除下一行的第0列单元格
                        tb.rows[i + 1].cells[col].style.display = 'none';
                        //更新rowSpan属性
                        tb.rows[startRow].cells[col].rowSpan = (tb.rows[startRow].cells[col].rowSpan | 0) + 1;
                        //当循环到终止行前一行并且起始行和终止行不相同时递归(因为上面的代码已经检查了i+1行，所以此处只到endRow-1)
                        if (i == endRow - 1 && startRow != endRow) {
                            MergeCell(tableId, startRow, endRow, col + 1);
                        }
                    } else {
                        //起始行，终止行不变，检查下一列
                        MergeCell(tableId, startRow, i, col + 1);
                        //增加起始行
                        startRow = i + 1;
                    }
                }
            }
			var message = "<#if message ??>${message}</#if>";
			if(!isEmpty(message)) {
				showMsg(message);
			}

			function showimage(source){
				$("#ShowImage_Form").find("#img_show").html("<image src='"+source+"' class='carousel-inner img-responsive img-rounded' />");
				$("#ShowImage_Form").modal();
			}

			$("#ShowImage_Form").click(function(){
				$("#ShowImage_Form").modal('hide');
			})

			var updateCode = function(obj){
				$("#isAdd").attr("disabled",false);
				$("#isAdd").attr("readOnly",false);
				var codeId = $(obj).attr("value");
				$.ajax({
					url : '${request.contextPath}/statisticCode/edit',
					type : "GET",
					data : {
						codeId:codeId
					},
					success:function(data) {
						if(data.code == 1) {
							$("#update").click();
							statisticCodeData = data.statisticCode;
							parentCodeData = data.parentCode;
							showIsAdd = data.showIsAdd;
							if (parentCodeData != null){
								$("#parent").attr("value",parentCodeData.id);
								$("#parentText").attr("value",parentCodeData.name);
							} else{
								$("#parent").attr("value",null);
								$("#parentText").attr("value","无");
							}
							$("#id").attr("value",statisticCodeData.id);
							$("#name").attr("value",statisticCodeData.name);
							$("#nameBak").attr("value",statisticCodeData.name);
							$("#enName").attr("value",statisticCodeData.enName);
							$("#code").attr("value",statisticCodeData.code);
							var options = $("#isAdd").find("option");
							var isAdd = statisticCodeData.isAdd;
							for(var i=0; i<options.length; i++){  
							    if(options.eq(i).val() == isAdd){ 
							        options.eq(i).attr("selected", true);  
							    }else{
							    	options.eq(i).attr("selected", false); 
							    }
							} 
							if(showIsAdd){
								$("#isAdd").attr("disabled",true);
								$("#isAdd").attr("readOnly",true);
							}
						} else {
							if(data.msg == undefined){
								showMsg("权限不足！");
							}else{
								showMsg(data.msg);
							}
						}
					},
					error:function(data) {
					}
				});
			}	
		
			jQuery(function($) {
				$("#save").click(function(){
					var id = $("#id").val();
					var parentId = $("#parent").val();
					var name = $("#name").val();
					var nameBak = $("#nameBak").val();
					var isNew = true;
					if (name == nameBak){
						isNew = false;
					}
					var enName = $("#enName").val();
					var code = $("#code").val();
					var isAdd = $("#isAdd").val();
					if(isEmpty(name)) {
						$("#name").focus();
						showMsg("中文名称不能为空！");
					} else if(isEmpty(enName)){
						$("#enName").focus();
						showMsg("名称拼音不能为空！");
					} else{
						$('#myModal').modal('hide');
						$.ajax({
							url : '${request.contextPath}/statisticCode/save',
							type : "POST",
							data : {
								id : id,
								parentId : parentId,
								name : name,
								enName : enName,
								code : code,
								isAdd : isAdd,
								isNew : isNew,
								nameBak : nameBak
							},
							success:function(data) {
								if(data.code == 1) {
									$("#searchForm").attr("action","${request.contextPath}/statisticCode/list?message="+data.msg);
									$("#searchForm").submit();
								}
							},
							error:function(data) {
							}
						});
					}
				});
			});

            /**
             * 翻页到指定页数
             */
            var showPage = function(page,obj) {
                var objId = $(obj).attr("id");//当前按钮的id
                var pages = $("#sp_1_grid-pager").html();//总页数
                var pageNum = $(".ui-pg-input").val();//当前页
                if(pageNum == pages){
                    if(objId == "next_grid-pager" || objId == "last_grid-pager"){
                        return;
                    }
                }
                if(pageNum == 1){
                    if(objId == "prev_grid-pager" || objId == "first_grid-pager"){
                        return;
                    }
                }
                $("td").attr("onclick","");
                var action = $("#searchForm").attr("action");
                $("#currentPage").val(page);
                action = action + "?currentPage=" + page;
                $("#searchForm").attr("action", action);
                $("#searchForm").submit();
            }

            $(".ui-pg-input").blur(function(){
                var objValue = $(".ui-pg-input").val();//文本框输入页数
                var pages = $("#sp_1_grid-pager").html();//总页数
                if(Number(objValue) > pages || Number(objValue) < 1){
                    return;
                }
                $("td").attr("onclick","");
                var action = $("#searchForm").attr("action");
                action = action + "?page=" + objValue;
                $("#searchForm").attr("action", action);
                $("#searchForm").submit();
            });

		</script>
	</body>
</html>